package com.niuke;

import java.util.Stack;

/**
 * @ClassName : NC52
 * @Author : kele
 * @Date: 2023/4/2 15:18
 * @Description :
 */
public class NC52 {

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(') {
                stack.push(')');
            } else if (c == '[') {
                stack.push('}');
            } else if (c == '{') {
                stack.push('}');
            }else if(!stack.isEmpty() && stack.pop()!=c){
                return false;
            }
        }
        return stack.isEmpty();
    }
}
